﻿using StructureMap;
using StructureMap.Attributes;
using Quickie.Models;
using Quickie.Models.IoC;
using Quickie.Models.Data;
using Quickie.Models.Entities;
using Quickie.Models.ViewModel;
using Quickie.Models.Interfaces;

namespace Quickie.Models.IoC
{
    /// <summary>
    /// Klasa zaduzena za inversion of controle
    /// </summary>
    public static class ContainerBootstrapper
    {
        /// <summary>
        /// Metoda koja postavlja defaultne klase za
        /// odredena sucelja.
        /// </summary>
        public static void BootstrappStructureMap()
        {
            ObjectFactory.Initialize(x =>
            {
                x.ForRequestedType<IDataProvider>()
                    .CacheBy(InstanceScope.Hybrid)
                    .TheDefaultIsConcreteType<L2SDataProvider>();

                x.ForRequestedType(typeof (IRepository<Product>))
                    .TheDefaultIsConcreteType(typeof (ProductRepository));

                x.ForRequestedType(typeof (IRepository<Category>))
                    .TheDefaultIsConcreteType(typeof (CategoryRepository));

                x.ForRequestedType(typeof(IRepository<Company>))
                    .TheDefaultIsConcreteType(typeof(CompanyRepository));

                x.ForRequestedType(typeof(IRepository<Person>))
                    .TheDefaultIsConcreteType(typeof(PersonRepository));

                x.ForRequestedType(typeof(IRepository<Task>))
                    .TheDefaultIsConcreteType(typeof(TaskRepository));
            });

        }
    }
}
